package com.yww.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yww.entity.Results;
import com.yww.entity.ResultsParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 雯雯yang
 * @since 2020-06-21
 */
public interface ResultsMapper extends BaseMapper<Results> {

    @Insert("insert into results (user_id,success_num,doing_num,create_time,count_num,percent_num) " +
            "select uid,num1,num2,date_format( NOW(),'%Y-%m-%d'), num3,IFNULL(CONCAT(left(num1/num3*100,5),'%'),'00.00%') num4 from " +
            "(select d.users_id uid,num1,IFNULL(num2,0) num2,num3  from " +
            "(select c.users_id ,IFNULL(num1,0) num1,num3 from  " +
            "(select users_id ,count(*) num3 from student where users_id is not null and month(create_time)=month(NOW()) group by users_id) c " +
            "left join " +
            "(select users_id, count(*) as num1 from student where is_pay=0 and is_tf=1 and  users_id is not null and month(create_time)=month(NOW()) group by users_id) a " +
            "on a.users_id=c.users_id " +
            ") d " +
            "left JOIN " +
            "(select users_id, count(*) as num2 from student where is_pay=1 and is_tf=1 and users_id is not null and month(create_time)=month(NOW()) group by users_id) b " +
            "on b.users_id=d.users_id) e " +
            "group by uid")
    boolean addResults();

    List<Results> getList(ResultsParam resultsParam);
    List<Results> getList2(ResultsParam resultsParam);

    List<Results> exportUsers(@Param("ids")String[] ids);

}
